package com.unitechs.controller.map;

import com.unitechs.controller.DevinfoTest;

import java.util.HashMap;
import java.util.Map;

public class PutIfAbsentTest {
    public static void main(String[] args) {
        Map<String,String> mapa=new HashMap<>();
        mapa.put("a","a");

        System.out.println(mapa);
        mapa.put("a","b");
        System.out.println(mapa);

        System.out.println();

        Map<String,String> mapb=new HashMap<>();
        mapb.putIfAbsent("b","b");
        System.out.println(mapb);

        mapb.putIfAbsent("b","a");
        System.out.println(mapb);

    }

    private static void mapMethod(){
        Map<String, DevinfoTest> map=new HashMap<>();

        DevinfoTest devinfoTest = map.get("a");

        if (devinfoTest==null){
            devinfoTest =new DevinfoTest();
            map.put("a",devinfoTest);
        }
        devinfoTest.setDevid("RD00001");
    }

    private static void mapMethodByAbsent(){
        Map<String, DevinfoTest> map=new HashMap<>();
        map.putIfAbsent("a",new DevinfoTest());
        DevinfoTest devinfoTest = map.get("a");
        devinfoTest.setDevid("RD00001");
    }


}
